﻿ @implements IDisposable
 
 <table  class="table  table-striped">
     <thead>
         <tr>
             <th scope="col">区域名称</th>
             <th scope="col">锁定情况</th> 
             <th scope="col">被锁列表</th> 
         </tr> 
     </thead>
     <tbody>
        @{ 
            foreach(var item in list)
            {
                <tr>
                    <td>@item.AreaID</td>
                    @if (item.Locked)
                    {
                        <td>已锁定，上锁AGV:@item.Owner</td>
                    }
                    else
                    { 
                         <td></td>
                   }
                    <td>@item.LockedAgv</td>
                   
                </tr>
            }
        }
     </tbody>
 </table>


@code {
   
    List<AreaSynthesisInfo> list = new List<AreaSynthesisInfo>();
    System.Timers.Timer timer = new System.Timers.Timer(1000);

    protected override void OnInitialized()
    {
        base.OnInitialized();
        timer.Elapsed += timerEvent;
        timer.Start();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);

    }

    async  void timerEvent(object? sender, System.Timers.ElapsedEventArgs e)
    {
        timer.Stop(); 
        var tmp = await WarningAreaDataSet.GetAllInfoAsync();
        list.Clear();
        if (tmp.Count > 0)
        {
            list.AddRange(tmp);
        }
        await InvokeAsync(StateHasChanged);
         timer.Start();
    }

     

    public void Dispose()
    {
        timer.Stop();
    }
    
}
